From 4cf69fddb45c52c21f5e9262ec3c6c4b2600ab5e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 13 Dec 2008 08:11:54 +0000 Subject: [PATCH] Allow out-of-order setting of model and active. Patch by Christian Dywan * gtk/gtkcombobox.c: Allow out-of-order setting of model and active. Patch by Christian Dywan svn path=/trunk/; revision=21888 --- ChangeLog | 7 +++++++ gtk/gtkcombobox.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 23e9ab42e8..75b6f85b03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-12-13 Matthias Clasen + + Bug 555560 – gtk_combo_box_set_active fails with no model + + * gtk/gtkcombobox.c: Allow out-of-order setting of model and active. + Patch by Christian Dywan + 2008-12-13 Matthias Clasen Bug 558306 – Cannot build gdk (gtk+ 2.14.4) on Solaris 8 diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index df6b601094..dc3aae1aa7 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -81,6 +81,7 @@ struct _GtkComboBoxPrivate gint wrap_width; GtkShadowType shadow_type; + gint active; /* Only temporary */ GtkTreeRowReference *active_row; GtkWidget *tree_view; @@ -928,6 +929,7 @@ gtk_combo_box_init (GtkComboBox *combo_box) priv->height = 0; priv->wrap_width = 0; + priv->active = -1; priv->active_row = NULL; priv->col_column = -1; priv->row_column = -1; @@ -4839,6 +4841,13 @@ gtk_combo_box_set_active (GtkComboBox *combo_box, g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); g_return_if_fail (index_ >= -1); + if (combo_box->priv->model == NULL) + { + /* Save index, in case the model is set after the index */ + combo_box->priv->active = index_; + return; + } + if (index_ != -1) path = gtk_tree_path_new_from_indices (index_, -1); @@ -5034,6 +5043,13 @@ gtk_combo_box_set_model (GtkComboBox *combo_box, gtk_cell_view_set_model (GTK_CELL_VIEW (combo_box->priv->cell_view), combo_box->priv->model); + if (combo_box->priv->active != -1) + { + /* If an index was set in advance, apply it now */ + gtk_combo_box_set_active (combo_box, combo_box->priv->active); + combo_box->priv->active = -1; + } + out: gtk_combo_box_update_sensitivity (combo_box); -- 2.30.2